		TITLE	DEFPUBS - Copyright (c) SLR Systems 1994

		INCLUDE MACROS
		INCLUDE	SYMBOLS
		INCLUDE	SEGMENTS
		INCLUDE	GROUPS
		INCLUDE	MODULES

		PUBLIC	DEFPUBS


		.DATA

		EXTERNDEF	SYMBOL_TEXT:BYTE

		EXTERNDEF	VECTOR_COUNT:DWORD,_END_GINDEX:DWORD,CURNMOD_GINDEX:DWORD,SYMBOL_LENGTH:DWORD,STACK_DELTA:DWORD
		EXTERNDEF	FIRST_MODULE_GINDEX:DWORD

		EXTERNDEF	SEGMOD_GARRAY:STD_PTR_S,MODULE_GARRAY:STD_PTR_S,SEGMENT_GARRAY:STD_PTR_S,SYMBOL_GARRAY:STD_PTR_S
		EXTERNDEF	GROUP_GARRAY:STD_PTR_S


		.CODE	MIDDLE_TEXT

		EXTERNDEF	SAY_VERBOSE:PROC,ERR_ASCIZ_ABORT:PROC

		EXTERNDEF	NO_BASE_SEG_ERR:ABS


DEFPUBS		PROC
		;
		;START AT BEGINNING OF PUBLIC LIST, AND DEFINE ALL PUBLIC
		;SYMBOLS AS COMPLETE OFFSETS WITH FRAME PARAGRAPH OR OS2_NUMBER
		;
		MOV	EAX,OFF DEFPUBS_MSG
		CALL	SAY_VERBOSE
if	any_overlays
		MOV	VECTOR_COUNT,0
endif
		MOV	ESI,FIRST_MODULE_GINDEX
		JMP	TEST_MODULE

		ASSUME	ESI:PTR SYMBOL_STRUCT
L0$:
		;
		;HMM, SEGMOD NOT LINKED ANYWHERE, MUST BE A VIRDEF I THREW AWAY...
		;
		MOV	AL,[ESI]._S_REF_FLAGS
		TEST	AL,MASK S_REFERENCED+MASK S_HARD_REF
		JZ	L08$
		;
		;OOPS, REFERENCED, FATAL ERROR HERE
		;
		LEA	ECX,[ESI]._S_NAME_TEXT
		MOV	AL,NO_BASE_SEG_ERR
		CALL	ERR_ASCIZ_ABORT

L08$:
		;
		;NOT REFERENCED, WHO CARES?  JUST FORCE LOCALNESS SO EVERYONE ELSE IGNORES IT
		;
		OR	AL,MASK S_SPACES

		MOV	[ESI]._S_REF_FLAGS,AL
		JMP	NEXT_PUBLIC


DEFPUB_LOOP:
		ASSUME	ESI:PTR SYMBOL_STRUCT
		;
		;FIRST DO OFFSET FROM SEGMENT PLEASE
		;
		CONVERT	EDI,EDI,SEGMOD_GARRAY
		ASSUME	EDI:PTR SEGMOD_STRUCT

if	any_overlays
		MOV	AL,ES:[DI]._SM_PLTYPE
		MOV	BX,ES:[DI]._SM_SECTION_GINDEX
		MOV	[SI]._S_PLTYPE,AL
		MOV	[SI]._S_SECTION_GINDEX,BX
endif
		MOV	ECX,[EDI]._SM_START			;OFFSET OF THIS SEGMOD FROM ITS SEGMENT
		MOV	EDI,[EDI]._SM_BASE_SEG_GINDEX

		MOV	[ESI]._S_SEG_GINDEX,EDI

		TEST	EDI,EDI
		JZ	L0$

		CONVERT	EDI,EDI,SEGMENT_GARRAY
		ASSUME	EDI:PTR SEGMENT_STRUCT

USE_GRP_RET:
		MOV	EBX,[ESI]._S_OFFSET
		MOV	EAX,[EDI]._SEG_OS2_NUMBER		;SEG_FRAME FOR REAL_MODE

		ADD	EBX,ECX
		MOV	EDX,[EDI]._SEG_OS2_FLAGS

		MOV	[ESI]._S_OFFSET,EBX

if	fg_segm OR fg_pe
		MOV	[ESI]._S_OS2_FLAGS,EDX
endif
if	fg_segm OR fg_pe
		GETT	BL,OUTPUT_SEGMENTED
		GETT	CL,OUTPUT_PE

		OR	BL,CL
		JNZ	L4$
endif

		MOV	BL,[ESI]._S_REF_FLAGS
		MOV	EDI,[EDI]._SEG_GROUP_GINDEX

		AND	BL,MASK S_USE_GROUP
		JZ	L3$

		TEST	EDI,EDI
		JZ	L3$

		CONVERT	EDI,EDI,GROUP_GARRAY
		ASSUME	EDI:PTR GROUP_STRUCT

		MOV	EAX,[EDI]._G_FRAME

L3$:
		SHR	EAX,4
L4$:
		MOV	[ESI]._S_OS2_NUMBER,EAX
if	any_overlays
		TEST	[SI]._S_PLINK_FLAGS,MASK VECTOR_YES
		JZ	NO_VECTOR
		MOV	AX,VECTOR_COUNT
		MOV	[SI]._S_VECTOR,AX
		INC	AX
		MOV	VECTOR_COUNT,AX
NO_VECTOR:
endif

NEXT_PUBLIC:
		POP	ESI
TEST_PUBLIC:
		TEST	ESI,ESI
		JZ	NEXT_MODULE

		CONVERT	ESI,ESI,SYMBOL_GARRAY
		ASSUME	ESI:PTR SYMBOL_STRUCT

		MOV	EBX,[ESI]._S_NEXT_SYM_GINDEX
		MOV	AL,[ESI]._S_NSYM_TYPE

		PUSH	EBX
		MOV	EDI,[ESI]._S_SEG_GINDEX	;MY SEGMOD

		CMP	AL,NSYM_CONST		;CONSTANTS ALREADY COMPLETELY DEFINED
		JNZ	DEFPUB_LOOP

		XOR	ECX,ECX

		MOV	[ESI]._S_OS2_NUMBER,ECX	;EXCEPT FOR FRAME, WHICH MUST BE ZERO
		MOV	[ESI]._S_OS2_FLAGS,ECX	;AND FRAME IS 32-BITS...

		POP	ESI
		JMP	TEST_PUBLIC

NEXT_MODULE:
		POP	ESI
TEST_MODULE:
		MOV	CURNMOD_GINDEX,ESI

		TEST	ESI,ESI
		JZ	MODS_DONE
DO_MODULE:
		CONVERT	ESI,ESI,MODULE_GARRAY
		ASSUME	ESI:PTR MODULE_STRUCT

		MOV	ECX,[ESI]._M_NEXT_MODULE_GINDEX
		MOV	ESI,[ESI]._M_FIRST_PUB_GINDEX

		PUSH	ECX
		JMP	TEST_PUBLIC

MODS_DONE:
		RET

DEFPUBS		ENDP


		.CONST

DEFPUBS_MSG	DB	SIZEOF DEFPUBS_MSG-1,'Assigning Symbol Addresses',0DH,0AH


		END

